package epoch.game.core.timer;

import epoch.game.core.action.IAction;
import epoch.game.core.actor.ATimer;

/**
 * 定时器
 * 
 * @author will
 * @date 2015年6月26日 下午7:56:58
 */
public abstract class GameTimer extends ATimer implements IAction {

	public GameTimer(long period) {
		super((int)period);
	}

	public GameTimer(long period, long repeat) {
		super((int)period, (int)repeat);
	}

	public GameTimer(long period, long repeat, long delay) {
		super((int)period, (int)repeat, (int)delay);
	}
	// 下一次执行时间
	private long nextActionTime;
	// 优先级
	boolean priority=true;
	// 固定间隔时间执行
	boolean fixedRate = true;


	public long getNextActionTime() {
		return nextActionTime;
	}

	public void setNextActionTime(long nextActionTime) {
		this.nextActionTime = nextActionTime;
	}
	public long getPeriod() {
		return period*10;
	}
	public int getRepeat() {
		return repeat;
	}
	public long getDelay() {
		return timeout*10;
	}
	
	public void setRepeat(int repeat) {
		this.repeat = repeat;
	}
	public void setDelay(int delay) {
		this.timeout = delay/10;
	}

	public boolean isFixedRate() {
		return fixedRate;
	}
	
	public void action() {
		if(isCanceled()){
			return;
		}
		doAction();
	}
	
	protected abstract void doAction();
}
